#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <string>
#include <vector>


class Helloworld
{
    private:
        std::string name;
        std::vector<boost::thread*> thrd_vec;
    public:
       Helloworld(std::string);
       void hello();
       void run();
       void startJobWorker(std::string);
};
class JobWorker
{
    private:
        std::string name;
    public:
        JobWorker(std::string);
        void work();
};
Helloworld::Helloworld(std::string name)
    : name(name)
{}

void Helloworld::hello()
{
    std::cout << "hello world " << name << std::endl;
}
void Helloworld::run()
{
    std::string a[3] = {"job1", "job2", "job3"};
    for(int i=0;i<3;i++)
        startJobWorker(a[i]);
    for(int i=0; i<thrd_vec.size();i++)
        thrd_vec[i]->join();
}
void Helloworld::startJobWorker(std::string name)
{
    JobWorker *jw = new JobWorker(name);
    boost::thread* thrd = new boost::thread(boost::bind(&JobWorker::work, jw));
    thrd_vec.push_back(thrd);
}
JobWorker::JobWorker(std::string name)
    : name(name)
{}
void JobWorker::work()
{
    for(int i=0; i<10; i++)
    {
        std::cout << "job worker " << name << std::endl;
        sleep(1);
    }
}
int main()
{
    Helloworld hw("Tim");
    hw.run();
    Helloworld *hw1 = new Helloworld("Jack"); 
    boost::thread thrd(boost::bind(&Helloworld::hello, hw1));
    thrd.join();
    delete hw1;
    return 0;
}

